"""
Simple translation dictionary for PDF Splitter.
This provides basic translation functionality without requiring .qm files.
"""

_TRANSLATIONS = {
    'en_US': {
        'PDF Splitter': 'PDF Splitter',
        'Main Toolbar': 'Main Toolbar',
        'Open PDF': 'Open PDF',
        'Split PDF': 'Split PDF',
        'Exit': 'Exit',
        'File': 'File',
        'Edit': 'Edit',
        'View': 'View',
        'Language': 'Language',
        'Help': 'Help',
        'Select All': 'Select All',
        'Deselect All': 'Deselect All',
        'Zoom In': 'Zoom In',
        'Zoom Out': 'Zoom Out',
        'Reset Zoom': 'Reset Zoom',
        'About': 'About',
        'Document Information': 'Document Information',
        'No document loaded': 'No document loaded',
        'Quick Split': 'Quick Split',
        'Split Each Page': 'Split Each Page',
        'Split into 2-Page Sections': 'Split into 2-Page Sections',
        'Custom Split...': 'Custom Split...',
        'Ready': 'Ready',
        'Open PDF File': 'Open PDF File',
        'PDF Files (*.pdf);;All Files (*)': 'PDF Files (*.pdf);;All Files (*)',
        'Error': 'Error',
        'File not found: %1': 'File not found: %1',
        'Loading PDF...': 'Loading PDF...',
        'Failed to load PDF': 'Failed to load PDF',
        'Failed to load PDF: %1': 'Failed to load PDF: %1',
        'Loaded: %1': 'Loaded: %1',
        'Title': 'Title',
        'Author': 'Author',
        'Unknown': 'Unknown',
        'Yes': 'Yes',
        'No': 'No',
        'Select Output Directory': 'Select Output Directory',
        'Splitting into %1-page files...': 'Splitting into %1-page files...',
        'About PDF Splitter': 'About PDF Splitter',
        'A cross-platform PDF file splitter application.': 'A cross-platform PDF file splitter application.',
        'Built with PyQt6 and PyMuPDF.': 'Built with PyQt6 and PyMuPDF.',
        'Page %1 selected': 'Page %1 selected',
        '%1 pages selected': '%1 pages selected',
        'No pages selected': 'No pages selected',
        'No preview available': 'No preview available',
        'No document loaded': 'No document loaded',
        'Fit': 'Fit',
        '%1 pages': '%1 pages',
        'Page %1': 'Page %1',
        'Page %1\n(Preview not available)': 'Page %1\n(Preview not available)',
        'This would split the PDF into files with %1 pages each.\nOutput directory: %2':
            'This would split the PDF into files with %1 pages each.\nOutput directory: %2',
        '<b>%1 v0.1.0</b><br><br>%2<br><br>%3': '<b>%1 v0.1.0</b><br><br>%2<br><br>%3',
    },
    'zh_CN': {
        'PDF Splitter': 'PDF 分割器',
        'Main Toolbar': '主工具栏',
        'Open PDF': '打开PDF',
        'Split PDF': '分割PDF',
        'Exit': '退出',
        'File': '文件',
        'Edit': '编辑',
        'View': '视图',
        'Language': '语言',
        'Help': '帮助',
        'Select All': '全选',
        'Deselect All': '取消全选',
        'Zoom In': '放大',
        'Zoom Out': '缩小',
        'Reset Zoom': '重置缩放',
        'About': '关于',
        'Document Information': '文档信息',
        'No document loaded': '未加载文档',
        'Quick Split': '快速分割',
        'Split Each Page': '每页分割',
        'Split into 2-Page Sections': '分割为2页一节',
        'Custom Split...': '自定义分割...',
        'Ready': '就绪',
        'Open PDF File': '打开PDF文件',
        'PDF Files (*.pdf);;All Files (*)': 'PDF文件 (*.pdf);;所有文件 (*)',
        'Error': '错误',
        'File not found: %1': '文件未找到：%1',
        'Loading PDF...': '正在加载PDF...',
        'Failed to load PDF': 'PDF加载失败',
        'Failed to load PDF: %1': 'PDF加载失败：%1',
        'Loaded: %1': '已加载：%1',
        'Title': '标题',
        'Author': '作者',
        'Unknown': '未知',
        'Yes': '是',
        'No': '否',
        'Select Output Directory': '选择输出目录',
        'Splitting into %1-page files...': '正在分割为%1页的文件...',
        'About PDF Splitter': '关于PDF分割器',
        'A cross-platform PDF file splitter application.': '一个跨平台的PDF文件分割应用程序。',
        'Built with PyQt6 and PyMuPDF.': '使用PyQt6和PyMuPDF构建。',
        'Page %1 selected': '已选择第%1页',
        '%1 pages selected': '已选择%1页',
        'No pages selected': '未选择页面',
        'No preview available': '无法预览',
        'No document loaded': '未加载文档',
        'Fit': '适应窗口',
        '%1 pages': '%1页',
        'Page %1': '第%1页',
        'Page %1\n(Preview not available)': '第%1页\n（无法预览）',
        'This would split the PDF into files with %1 pages each.\nOutput directory: %2':
            '这将把PDF分割为每个文件包含%1页。\n输出目录：%2',
        '<b>%1 v0.1.0</b><br><br>%2<br><br>%3': '<b>%1 v0.1.0</b><br><br>%2<br><br>%3',
    }
}

def translate(text: str, language_code: str = 'en_US', **kwargs) -> str:
    """
    Get translation for a text string with placeholder support.

    Args:
        text: Text to translate with placeholders like %1, %2, etc.
        language_code: Language code ('en_US' or 'zh_CN')
        **kwargs: Placeholder values (e.g., arg1='value', arg2='value2')

    Returns:
        Translated text with placeholders replaced
    """
    translations = _TRANSLATIONS.get(language_code, _TRANSLATIONS['en_US'])
    translated = translations.get(text, text)

    # Replace placeholders
    for key, value in kwargs.items():
        if key.startswith('arg'):
            try:
                # Extract number from arg1, arg2, etc.
                num = int(key[3:])
                placeholder = f"%{num}"
                translated = translated.replace(placeholder, str(value))
            except (ValueError, IndexError):
                pass

    return translated